<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
  <head th:replace="fragments :: html_head('Product Overview','none')"></head>
  <body>
    <div th:fragment="content" th:remove="tag">
      <div>
        <div class="form-group row">
          <input
            type="text"
            class="form-control"
            placeholder="Product Name *"
            th:field="*{name}"
            th:readonly="${#authorization.expression('hasAuthority(''Sales'')')}"
            required
            minlength="2"
            maxlength="256"
          />
        </div>
        <div class="form-group row">
          <input
            type="text"
            class="form-control"
            placeholder="Product Alias: product name (spaces replaced by underscores)"
            th:field="*{alias}"
            th:readonly="${#authorization.expression('hasAuthority(''Sales'')')}"
            required
            minlength="2"
            maxlength="256"
          />
        </div>
        <div class="form-group row">
          <label class="form-label">Select a brand:</label>
          <th:block sec:authorize="hasAnyAuthority('Admin', 'Editor')">
            <select class="form-control select" required th:field="*{brand}">
              <th:block th:each="brand: ${brands}">
                <option th:value="${brand.id}">[[${brand.name}]]</option>
              </th:block>
            </select>
          </th:block>
          <th:block sec:authorize="hasAuthority('Sales')">
            <input
              type="text"
              class="form-control"
              th:value="${product.brand.name}"
              readonly
            />
          </th:block>
        </div>
        <div class="form-group row">
          <label class="form-label">Select a category:</label>
          <th:block sec:authorize="hasAnyAuthority('Admin', 'Editor')">
            <th:block th:if="${product.category != null}">
              <select th:field="*{category}" class="form-control" required>
                <th:block th:each="category : ${product.brand.categories}">
                  <option th:value="${category.id}">
                    [[${category.name}]]
                  </option>
                </th:block>
              </select>
            </th:block>

            <th:block th:if="${product.category == null}">
              <select
                th:field="*{category}"
                class="form-control"
                required
              ></select>
            </th:block>
          </th:block>
          <th:block sec:authorize="hasAuthority('Sales')">
            <input
              type="text"
              class="form-control"
              th:value="${product.category.name}"
              readonly
            />
          </th:block>
        </div>
        <div class="form-group ml-4 mt-3">
          <input
            type="checkbox"
            class="form-check-input"
            placeholder="Enabled"
            th:field="*{enabled}"
            th:disabled="${#authorization.expression('hasAuthority(''Sales'')')}"
            id="isEnabled"
          />
          <label class="form-check-label" for="isEnabled"> Enabled </label>
        </div>
        <div class="form-group row">
          <label class="form-label">Stock:</label>
          <input
            type="number"
            class="form-control"
            placeholder="Product number in stock *"
            th:field="*{stock}"
          />
        </div>
        <div class="form-group row">
          <label class="form-label">Cost:</label>
          <input
            type="number"
            class="form-control"
            placeholder="Product Cost *"
            th:field="*{cost}"
          />
        </div>
        <div class="form-group row">
          <label class="form-label">Price:</label>
          <input
            type="number"
            class="form-control"
            placeholder="Product Price *"
            th:field="*{price}"
          />
        </div>
        <div class="form-group row">
          <label class="form-label">Discount Percentage:</label>
          <input
            type="number"
            class="form-control"
            placeholder="Product Discount Percentage *"
            th:field="*{discountPercentage}"
          />
        </div>
      </div>
    </div>
  </body>
</html>
